﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using METU_CMT.Business;

namespace METU_CMT
{
    public partial class TeachingAssistantMainScreen : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindTeachingAssistantInfo();
                BindCourses();
            }
        }

        public void BindTeachingAssistantInfo()
        {
            TeachingAssistant _teachingAssistant = (TeachingAssistant)EntityFactory.User;
            SetTeachingAssistantInfo(_teachingAssistant);
        }

        private void SetTeachingAssistantInfo(TeachingAssistant teachingAssistant)
        {
            imgTA.ImageUrl = teachingAssistant.PhotoFile;

            lblUserName.Text = teachingAssistant.UserName;
            lblNameSurname.Text = teachingAssistant.Name + " " + teachingAssistant.Surname;
            lblEMail.Text = teachingAssistant.Email;
        }

        protected void OnLnkBtnEditProfileClicked(object sender, EventArgs e)
        {
            Response.Redirect("~/EditProfileScreen.aspx");
        }

        protected void BindCourses()
        {
            TeachingAssistant _teachingAssistant = (TeachingAssistant)EntityFactory.User;
            dtgCourses.DataSource = EntityFactory.GetCourseOfTeachingAssistant(_teachingAssistant.UserId);
            dtgCourses.DataBind();
        }

        protected void OnLnkBtnCourseNameClicked(object sender, EventArgs e)
        {
            int _courseId = CommonMethods.GetIdFromGridViewRow((GridViewRow)(((LinkButton)sender).NamingContainer));
            EntityFactory.CourseId = _courseId;
            CourseTA _course = new CourseTA(_courseId);
            _course.GoToCourseMainPage(Response);
        }
    }
}